//
//  XMWeiboTool.m
//  XMWeibo
//
//  Created by chi on 14-8-22.
//  Copyright (c) 2014年 xiaoming. All rights reserved.
//

#import "XMWeiboTool.h"

#import "XMTabBarController.h"
#import "XMOAuthController.h"
#import "XMNewFeatureController.h"
#import "XMWeiboAccount.h"

#import "XMNavigationController.h"


@implementation XMWeiboTool

+ (void)chooseRootViewController
{
    [XMWeiboAccount loadAccount];
    XMWeiboAccount *account = [XMWeiboAccount account];
    
    UIApplication *app = [UIApplication sharedApplication];
    
    if (!account || account.isExpireAccount) {//帐号过期
         app.statusBarHidden = NO;
        
        XMOAuthController *oauth = [[XMOAuthController alloc]init];
        oauth.navigationItem.title = @"微博授权";
        XMNavigationController *nav = [[XMNavigationController alloc]initWithRootViewController:oauth];
        
        app.keyWindow.rootViewController = nav;
        
    }
    else {
        
        NSString *nowVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];
        
        NSString *saveVersion = [[NSUserDefaults standardUserDefaults]valueForKey:@"CFBundleVersion"];
        
        if ([nowVersion isEqualToString:saveVersion]) {
            app.statusBarHidden = NO;
            XMTabBarController *controller = [[XMTabBarController alloc]init];
            [app.keyWindow setRootViewController:controller];
        }
        else {
            XMNewFeatureController *newFeature = [[XMNewFeatureController alloc]init];
            [app.keyWindow setRootViewController:newFeature];
            
            [[NSUserDefaults standardUserDefaults] setValue:nowVersion forKey:@"CFBundleVersion"];
            [[NSUserDefaults standardUserDefaults]synchronize];
        }

    }
    
}

@end
